
*------------------------------------------------------------------------------*
* Test 7: with number of active/new address
*------------------------------------------------------------------------------*
*------------ 1. Clean the data
*--- 1-1 Active address
insheet using "data/source/bitcoin-number-of-active-addresses.csv", clear
gen currency_id = "bitcoin"
save "data/working/bitcoin_activeaddress", replace

insheet using "data/source/ethereum-number-of-active-addresses.csv", clear
gen currency_id = "ethereum"
save "data/working/ethereum_activeaddress", replace

insheet using "data/source/litecoin-number-of-active-addresses.csv", clear
gen currency_id = "litecoin"
save "data/working/litecoin_activeaddress", replace

*--- 1-2 New address
insheet using "data/source/bitcoin-number-of-new-addresses.csv", clear
gen currency_id = "bitcoin"
save "data/working/bitcoin_newaddress", replace

insheet using "data/source/ethereum-number-of-new-addresses.csv", clear
gen currency_id = "ethereum"
save "data/working/ethereum_newaddress", replace

insheet using "data/source/litecoin-number-of-new-addresses.csv", clear
gen currency_id = "litecoin"
save "data/working/litecoin_newaddress", replace


*--- 1-3 Active address Combine 
use "data/working/bitcoin_activeaddress", clear
append using "data/working/ethereum_activeaddress"
append using "data/working/litecoin_activeaddress"

gen odate = substr(activeaddressest,1,10)
gen date = date(odate,"YMD")
rename activeaddressesv num_activeaddress
keep date currency_id num_activeaddress
order date currency_id num_activeaddress

encode currency_id, gen(dcurrency_id)
xtset dcurrency_id date
gen L7_num_activeaddress = L7.num_activeaddress
gen L14_num_activeaddress = L14.num_activeaddress
drop dcurrency_id

save "data/working/num_activeaddress", replace

*--- 1-4 Active address Bitcoin and all others
use "data/working/bitcoin_activeaddress", clear
gen odate = substr(activeaddressest,1,10)
gen date = date(odate,"YMD")
rename activeaddressesv num_activeaddress_Bitcoin
keep date num_activeaddress_Bitcoin
order date num_activeaddress_Bitcoin
tset date
gen L7_num_activeaddress_Bitcoin =  L7.num_activeaddress_Bitcoin
gen L14_num_activeaddress_Bitcoin =  L14.num_activeaddress_Bitcoin
save "data/working/num_activeaddress_Bitcoin", replace

*--- 1-5 New address Combine 
use "data/working/bitcoin_newaddress", clear
append using "data/working/ethereum_newaddress"
append using "data/working/litecoin_newaddress"

gen odate = substr(newaddressest,1,10)
gen date = date(odate,"YMD")
rename newaddressesv num_newaddress
keep date currency_id num_newaddress
order date currency_id num_newaddress

encode currency_id, gen(dcurrency_id)
xtset dcurrency_id date
gen L7_num_newaddress = L7.num_newaddress
gen L14_num_newaddress = L14.num_newaddress
drop dcurrency_id

save "data/working/num_newaddress", replace

*--- 1-6 New address Bitcoin and all others
use "data/working/bitcoin_newaddress", clear
gen odate = substr(newaddressest,1,10)
gen date = date(odate,"YMD")
rename newaddressesv num_newaddress_Bitcoin
keep date num_newaddress_Bitcoin
order date num_newaddress_Bitcoin
tset date
gen L7_num_newaddress_Bitcoin = L7.num_newaddress_Bitcoin
gen L14_num_newaddress_Bitcoin = L14.num_newaddress_Bitcoin

save "data/working/num_newaddress_Bitcoin", replace
